package com.xuxingcan.findmyvoice.Util;

import android.content.Context;
import android.media.AudioManager;
import android.util.Log;

/**
 * Created by Administrator on 2016/3/29.
 */
public class AudioUtil {
    public static boolean muteAudioFocus(Context context, boolean bMute) {
        if (context == null) {
            return false;
        }
        boolean bool = false;
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (bMute) {
            int result = am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
            bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
        } else {
            int result = am.abandonAudioFocus(null);
            bool = result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
        }
        return bool;
    }
}
